package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    private ManageService manageService;

    /**
     *  分页查询用户数据
     */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = manageService.findAllUsers(page,pagesize);
        return ResponseEntity.ok(pr);
    }

    /**
     *  查询用户基本资料
     */
    @GetMapping("/users/{userId}")
    public ResponseEntity findById(@PathVariable("userId") Long userId){
        return manageService.findById(userId);
    }

    /**
     *  分页查看用户视频记录
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid){
       PageResult pr = manageService.findVideos(uid,page,pagesize);
       return ResponseEntity.ok(pr);
    }

    /**
     *  查询指定用户发布的所有动态
     */
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid,Integer state){
        PageResult result = manageService.findAllMovement(page,pagesize,uid,state);
        return ResponseEntity.ok(result);
    }

    /**
     *  查询动态详情
     */
    @GetMapping("/messages/{id}")
    public ResponseEntity findMovementById(@PathVariable("id") String id){
        MovementsVo vo = manageService.findMovementById(id);
        return ResponseEntity.ok(vo);
    }

    /**
     *  分页查询评论列表
     */
    @GetMapping("/messages/comments")
    public ResponseEntity findComments(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String messageID){
        PageResult pr = manageService.findComments(page,pagesize,messageID);
        return ResponseEntity.ok(pr);
    }
}
